/**
 * 替换转义字符，使用switch语句
 */

#include <stdio.h>

#define MAXLINE 1000

void escape(char s[], char t[]);
    
int main() {
    char s[MAXLINE];
    char t[] = "Hello,\tworld!\n";
    printf("%s", t);
    escape(s, t);
    printf("%s", s);

    return 0;
}

void escape(char s[], char t[]) {
    int i, j;
    i = j = 0;
    while (t[i]) {
        switch(t[i]) {
            case '\t':
                s[j++] = '\\';
                s[j++] = 't';
                break;
            case '\n':
                s[j++] = '\\';
                s[j++] = 'n';
                break;
            default:
                s[j++] = t[i];
                break;
        }
        i++;
    }
    s[j] = '\0';
}
